package org.example.minebackend.mapper;

import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.annotations.*;
import org.example.minebackend.pojo.Herb;
import org.example.minebackend.pojo.IngredientOfRecipe;
import org.example.minebackend.pojo.Recipe;
import org.example.minebackend.pojo.Step;

import java.util.List;

@Mapper
public interface HealthClubMapper {
    @Select("select * from chinese_medicine.recipes where body=#{body}")
    List<Recipe> getRecipeByBody(String body);

    @Select("select * from chinese_medicine.ingredientofrecipe where recipeId=#{recipeId}")
    List<IngredientOfRecipe> getIngredientsByRecipeId(Integer recipeId);

    @Select("select * from chinese_medicine.recipes where id=#{id}")
    Recipe getRecipeById(Integer id);

    @Select("select * from chinese_medicine.orderofrecipe where recipeId=#{recipeId} order by `order`")
    List<Step> getStepsById(Integer recipeId);

    @Select("select * from chinese_medicine.herbs where body=#{body}")
    List<Herb> getHerbsByBody(String body);

    @Update("update chinese_medicine.recipes set nOfCollections = nOfCollections + 1 where id = #{id}")
    void addRecipeCollectionById(Integer id);

    @Insert("insert into chinese_medicine.recipesofcollection values (#{userId}, #{recipeId})")
    void insertRecipeCollectionById(Integer userId, Integer recipeId);

    @Select("select count(*) from chinese_medicine.recipesofcollection where userId=#{userId} and recipeId=#{recipeId}")
    Integer judgeCollection(Integer userId, Integer recipeId);

    @Update("update chinese_medicine.recipes set nOfCollections = nOfCollections - 1 where id = #{id}")
    void deleteRecipeCollectionById(Integer id);

    @Delete("delete from recipesofcollection where recipeId=#{recipeId} and userId=#{userId}")
    void deleteRecipeCollectionByTwoId(Integer userId, Integer recipeId);
}
